using GroupSix.Domain.Entity;

namespace GroupSix.Domain.Entity.App;

/// <summary>
/// 文章实体
/// </summary>
public class GsArticle : EntityBase
{
    /// <summary>
    /// 文章标题
    /// </summary>
    public string Title { get; set; } = string.Empty;

    /// <summary>
    /// 文章内容（富文本）
    /// </summary>
    public string Content { get; set; } = string.Empty;

    /// <summary>
    /// 文章摘要
    /// </summary>
    public string Summary { get; set; } = string.Empty;

    /// <summary>
    /// 文章分类ID
    /// </summary>
    public Guid CategoryId { get; set; }

    /// <summary>
    /// 文章分类名称
    /// </summary>
    public string CategoryName { get; set; } = string.Empty;

    /// <summary>
    /// 文章标签（JSON格式存储）
    /// </summary>
    public string Tags { get; set; } = string.Empty;

    /// <summary>
    /// 文章状态 (draft: 草稿, published: 发布, offline: 下线)
    /// </summary>
    public string Status { get; set; } = "draft";

    /// <summary>
    /// 作者ID
    /// </summary>
    public Guid AuthorId { get; set; }

    /// <summary>
    /// 作者名称
    /// </summary>
    public string AuthorName { get; set; } = string.Empty;

    /// <summary>
    /// 封面图片URL
    /// </summary>
    public string CoverImage { get; set; } = string.Empty;

    /// <summary>
    /// 阅读量
    /// </summary>
    public int ViewCount { get; set; } = 0;

    /// <summary>
    /// 点赞数
    /// </summary>
    public int LikeCount { get; set; } = 0;

    /// <summary>
    /// 评论数
    /// </summary>
    public int CommentCount { get; set; } = 0;

    /// <summary>
    /// 发布时间
    /// </summary>
    public DateTime? PublishedAt { get; set; }

    /// <summary>
    /// SEO标题
    /// </summary>
    public string SeoTitle { get; set; } = string.Empty;

    /// <summary>
    /// SEO关键词
    /// </summary>
    public string SeoKeywords { get; set; } = string.Empty;

    /// <summary>
    /// SEO描述
    /// </summary>
    public string SeoDescription { get; set; } = string.Empty;

    /// <summary>
    /// 是否置顶
    /// </summary>
    public bool IsTop { get; set; } = false;

    /// <summary>
    /// 是否推荐
    /// </summary>
    public bool IsRecommend { get; set; } = false;

    /// <summary>
    /// 排序权重
    /// </summary>
    public int SortWeight { get; set; } = 0;

    /// <summary>
    /// 构造函数
    /// </summary>
    public GsArticle(string title, string content, Guid categoryId, string categoryName, Guid authorId, string authorName)
    {
        Title = title;
        Content = content;
        CategoryId = categoryId;
        CategoryName = categoryName;
        AuthorId = authorId;
        AuthorName = authorName;
        Status = "draft";
        ViewCount = 0;
        LikeCount = 0;
        CommentCount = 0;
        IsTop = false;
        IsRecommend = false;
        SortWeight = 0;
    }

    /// <summary>
    /// 更新文章基本信息
    /// </summary>
    public void UpdateBasicInfo(string title, string content, string summary, Guid categoryId, string categoryName, string tags)
    {
        Title = title;
        Content = content;
        Summary = summary;
        CategoryId = categoryId;
        CategoryName = categoryName;
        Tags = tags;
        UpdatedAt = DateTime.UtcNow;
    }

    /// <summary>
    /// 更新SEO信息
    /// </summary>
    public void UpdateSeoInfo(string seoTitle, string seoKeywords, string seoDescription)
    {
        SeoTitle = seoTitle;
        SeoKeywords = seoKeywords;
        SeoDescription = seoDescription;
        UpdatedAt = DateTime.UtcNow;
    }

    /// <summary>
    /// 发布文章
    /// </summary>
    public void Publish()
    {
        Status = "published";
        PublishedAt = DateTime.UtcNow;
        UpdatedAt = DateTime.UtcNow;
    }

    /// <summary>
    /// 下线文章
    /// </summary>
    public void Offline()
    {
        Status = "offline";
        UpdatedAt = DateTime.UtcNow;
    }

    /// <summary>
    /// 设置为草稿
    /// </summary>
    public void SetAsDraft()
    {
        Status = "draft";
        UpdatedAt = DateTime.UtcNow;
    }

    /// <summary>
    /// 增加阅读量
    /// </summary>
    public void IncrementViewCount()
    {
        ViewCount++;
    }

    /// <summary>
    /// 增加点赞数
    /// </summary>
    public void IncrementLikeCount()
    {
        LikeCount++;
    }

    /// <summary>
    /// 减少点赞数
    /// </summary>
    public void DecrementLikeCount()
    {
        if (LikeCount > 0)
            LikeCount--;
    }

    /// <summary>
    /// 增加评论数
    /// </summary>
    public void IncrementCommentCount()
    {
        CommentCount++;
    }

    /// <summary>
    /// 减少评论数
    /// </summary>
    public void DecrementCommentCount()
    {
        if (CommentCount > 0)
            CommentCount--;
    }

    /// <summary>
    /// 设置置顶状态
    /// </summary>
    public void SetTopStatus(bool isTop)
    {
        IsTop = isTop;
        UpdatedAt = DateTime.UtcNow;
    }

    /// <summary>
    /// 设置推荐状态
    /// </summary>
    public void SetRecommendStatus(bool isRecommend)
    {
        IsRecommend = isRecommend;
        UpdatedAt = DateTime.UtcNow;
    }

    /// <summary>
    /// 更新排序权重
    /// </summary>
    public void UpdateSortWeight(int sortWeight)
    {
        SortWeight = sortWeight;
        UpdatedAt = DateTime.UtcNow;
    }
} 